var len= 0 ;
function MonsterManager(levelManager, pointManager) {
  var info = levelManager.getLevelInfo();

  this.level = info.level;
  this.times = info.times;
  this.data = info.enemys;

  this.monsters = [];
  this.index = 0;
  this.length = 0;
  this.pointManager = pointManager;
  this.timer = [];
}

MonsterManager.prototype.makeOne = function() {
  this.monsters[this.index] = this.monsters[this.index] || {};
  var indexInfo = this.data[this.index];
  var monster;
  if (this.length >= indexInfo.maxLength) {
    game.time.events.remove(this.timer[this.index]);
    this.timer[this.index] = null;
    return ;
  }
  console.log(indexInfo.name)
   
  switch(indexInfo.name) {
    case 'enemy1':
      monster = new MonsterOne(this.pointManager);
      break;
    case 'enemy2':
      monster = new MonsterTwo(this.pointManager);
      break;
    case 'enemy3':
      monster = new MonsterTwo(this.pointManager);
      break;
  }

  monster.init();
  this.monsters[this.index][monster.id] = monster;
  this.length ++;
};


MonsterManager.prototype.make = function() {
  var indexInfo = this.data[this.index];

  this.timer[this.index] = game.time.events.loop(Phaser.Timer.SECOND * (indexInfo.loopTime), this.makeOne, this);
};

MonsterManager.prototype.getMonsters = function() {
  return this.monsters[this.index];
}

MonsterManager.prototype.getAlivesLength = function() {
  var len = 0;
  for(var i in this.monsters[this.index]) {
    if (this.monsters[this.index][i].alive) {
      len ++;
    }
  }
  return len;
};

MonsterManager.prototype.next = function() {
  if (this.index >= this.times - 1) {
    console.log('next level');
    return ;
  }
  this.index ++;
  this.length = 0;
  this.monsters[this.index] = {};
  return this.make();
}
